﻿//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: IStorageCommandBuilder.cs
//
//  Description: Provides the possibility to create storage commands.
// 
//--------------------------------------------------------------------------

using System;
using Chili.Opf3.Query;
using Chili.Opf3.Query.OPathParser;

namespace Chili.Opf3.Storages
{
	/// <summary>
	/// This interface is implemented by classes that create storage dependent commands from storage 
	/// independent queries.
	/// </summary>
	/// <remarks>
	/// This interface is implemented by classes that create storage commands from
	/// storage independent queries such as <see cref="Opf3.Query.ObjectQuery{T}">ObjectQuery</see>.
	/// For an implementation look in <see cref="Opf3.Storages.SqlCommandBuilderBase">SqlCommandBuilderBase</see>
	/// class or any other class that derives from the 
	/// <see cref="Opf3.Storages.SqlCommandBuilderBase">SqlCommandBuilderBase</see> class.
	/// </remarks>
	public interface IStorageCommandBuilder
	{
		/// <summary>
		/// Converts the <see cref="Opf3.Query.IQuery">IQuery</see> to
		/// a storage dependent <see cref="Opf3.Query.CompiledQuery">CompiledQuery</see>. This method should only be
		/// called by a class that implements the <see cref="IQuery">IQuery</see> interface.
		/// </summary>
		/// <param name="query"><see cref="Opf3.Query.IQuery">Query</see> object
		/// that is converted to a storage dependent <see cref="Opf3.Query.CompiledQuery">CompiledQuery</see>.
		/// </param>
		/// <param name="storage">The storage that the query is compiled for.</param>
		/// <returns>A storage dependent <see cref="Opf3.Query.CompiledQuery">CompiledQuery</see>.</returns>
		CompiledQuery ToCompiledQuery(IStorage storage, IQuery query);

		/// <summary>
		/// Returns whether the <see cref="IStorageCommandBuilder">IStorageCommandBuilder</see> supports 
		/// the query type on the given storage.
		/// </summary>
		/// <param name="storage">The storage for which the query should be compiled.</param>
		/// <param name="query">The query that should be compiled to a storage dependent command.</param>
		/// <returns>True if the query can be parsed by the <see cref="IStorageCommandBuilder">IStorageCommandBuilder</see>.</returns>
		bool IsSupported(IStorage storage, IQuery query);
	}
}
